/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.gzchengguo.cn
* 注意：
* 本软件为www.gzchengguo.cn开发研制，未经购买不得商用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package link.chengguo.orangemall.modules.product.rest;

import link.chengguo.orangemall.enums.ShopCommonEnum;
import link.chengguo.orangemall.logging.aop.log.Log;
import link.chengguo.orangemall.modules.aop.ForbidSubmit;
import link.chengguo.orangemall.modules.product.domain.OrangeStoreProductReply;
import link.chengguo.orangemall.modules.product.service.OrangeStoreProductReplyService;
import link.chengguo.orangemall.modules.product.service.dto.OrangeStoreProductReplyQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
* @author chengguo
* @date 2019-11-03
*/
@Api(tags = "商城:评论管理")
@RestController
@RequestMapping("api")
public class StoreProductReplyController {


    private final OrangeStoreProductReplyService orangeStoreProductReplyService;

    public StoreProductReplyController(OrangeStoreProductReplyService orangeStoreProductReplyService) {
        this.orangeStoreProductReplyService = orangeStoreProductReplyService;
    }

    @Log("查询")
    @ApiOperation(value = "查询")
    @GetMapping(value = "/orangeStoreProductReply")
    @PreAuthorize("hasAnyRole('admin','ORANGESTOREPRODUCTREPLY_ALL','ORANGESTOREPRODUCTREPLY_SELECT')")
    public ResponseEntity getOrangeStoreProductReplys(OrangeStoreProductReplyQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(orangeStoreProductReplyService.queryAll(criteria,pageable),HttpStatus.OK);
    }



    @Log("修改")
    @ApiOperation(value = "修改")
    @PutMapping(value = "/orangeStoreProductReply")
    @PreAuthorize("hasAnyRole('admin','ORANGESTOREPRODUCTREPLY_ALL','ORANGESTOREPRODUCTREPLY_EDIT')")
    public ResponseEntity update(@Validated @RequestBody OrangeStoreProductReply resources){
        resources.setMerchantReplyTime(new Date());
        resources.setIsReply(ShopCommonEnum.REPLY_1.getValue());
        orangeStoreProductReplyService.updateById(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }

    @ForbidSubmit
    @Log("删除")
    @ApiOperation(value = "删除")
    @DeleteMapping(value = "/orangeStoreProductReply/{id}")
    @PreAuthorize("hasAnyRole('admin','ORANGESTOREPRODUCTREPLY_ALL','ORANGESTOREPRODUCTREPLY_DELETE')")
    public ResponseEntity delete(@PathVariable Long id){
        orangeStoreProductReplyService.removeById(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}
